package com.swust.exam.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.swust.exam.pojo.Course;
import com.swust.exam.pojo.Teachers;
import com.swust.exam.service.TeachersService;

@Controller
@RequestMapping("/teacher")
public class TeachersController {
	@Autowired
	public TeachersService teachersService;
	@RequestMapping(value="/delete")
   public String teacherDelete(Integer id, Model model){
	 teachersService.delete(id);
	 List<Teachers> list=teachersService.teacherlist();
	 model.addAttribute("teacherlist",list);
	 return  "teachers";
}
	@RequestMapping(value="/insert",method= RequestMethod.POST)
	public String teacherInsert(Teachers teachers,Model model){
		teachersService.insert(teachers);
		List<Teachers> list=teachersService.teacherlist();
		model.addAttribute("teacherlist",list);
		return "teachers";
	}
	
	@RequestMapping(value="/update",method=RequestMethod.POST)
	public String teacherUpdate(Teachers teachers,Model model){
		teachersService.update(teachers);
		List<Teachers> list=teachersService.teacherlist();
		model.addAttribute("teacherlist",list);
		return "teachers";
	}
}
